angular.module('tab-myself', [])

.controller 'TabMyselfCtrl', ($scope, $state, $ionicHistory,areaData,mallInfo,$ionicViewSwitcher,userData,$http,$ionicPopup) ->
    $scope.goPersonalInfo = ->
        $state.go 'tab.personal-info'
    $scope.goShopManage = ->
        $state.go 'tab.shop-manage-myself'
    $scope.goEmailBind = ->
        $state.go 'tab.email-bind'
    $scope.goAbout = ->
        $state.go 'tab.about'
    $scope.goMessageList = ->
        $state.go 'tab.message-list-myself'
    loadInfo=()->
        $http.get '/seller',params:{action:'showshop',userid:userData.getToken()}
        .success (resp) ->
            console.log resp
            mallInfo.mall=resp
            if mallInfo.mall.logo == ''
                mallInfo.mall.logo='img/img-picker/img-add.png'
            if mallInfo.mall.bannerimg == ''
                mallInfo.mall.bannerimg='img/img-picker/img-add.png'
            $scope.infoData={
                logo:resp.logo
                sitename:resp.sitename
                username:resp.username
                siteurl:resp.firsturl+'.upd365.com'
            }
    loadProvinceData=()->
        #获取地区信息,即省市列表
        if areaData.provinceList?.length==0 or areaData.cityList.length==0
            $http.get('/seller/',params:{action:'areadata'})
            .success (resp) ->
                if resp.status == '0' and resp.body?.length>=2
                    areaData.provinceList = resp.body[0].province
                    areaData.cityList=resp.body[1].city
    $scope.$on '$ionicView.enter',->
        loadInfo()
        loadProvinceData() #获取省市信息,显示商家地址需要
    _.extend $scope,
        copy:->
#            $cordovaClipboard.copy('http://'+$scope.infoData.siteurl)
            console.log('http://'+$scope.infoData.siteurl)
        editMallInfo:->
            $state.go 'tab.mall-info-myself'
        editMallLogo:->
            $state.go 'tab.mall-logo-myself'
        goChangePwd:->
            $state.go 'tab.update-pwd'
        goAddress:->
            $state.go 'tab.address-list'
        goContact:->
            $state.go 'tab.contact-way'
        goEmail:->
            if mallInfo.mall.username==undefined
                return
            $state.go 'tab.email-bind'
        goSellerAddr:->
            if mallInfo.mall.username==undefined
                return
            $state.go 'tab.seller-address',{address:mallInfo.mall?.address}
        logout: ->
            userData.reset()
            $ionicHistory.clearCache()
            $ionicHistory.nextViewOptions {disableBack: true}
            $state.go 'entrance'
